<!DOCTYPE html>
<html lang="en">

<head>
    <title></title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="./vue2.js"></script>
<link rel="stylesheet" href="./animate.css">
    <style>
        #app {
            width: 600px;
            margin: 10px auto;
        }

        .tb {
            border-collapse: collapse;
            width: 100%;
        }

        .tb th {
            background-color: #0094ff;
            color: white;
        }

        .tb td,
        .tb th {
            padding: 5px;
            border: 1px solid black;
            text-align: center;
        }

        .add {
            padding: 5px;
            border: 1px solid black;
            margin-bottom: 10px;
        }
    </style>
</head>

<body>
    <div id="app">
        <div class="add">
            编号:
            <input type="text" v-model="newId" ref="inputRefId"> 品牌名称:
            <input type="text" v-model="newName">
            <input type="button" value="添加" @click="addData">
        </div>

        <div class="add">
            品牌名称:
            <input type="text" placeholder="请输入搜索条件">
        </div>

        <div>
            <table class="tb">
                <tr>
                    <th>编号</th>
                    <th>品牌名称</th>
                    <th>创立时间</th>
                    <th>操作</th>
                </tr>
                <tr v-for="(item,index) in  list" :key="index">
                    <td>{{item.id}}</td>
                    <td>{{item.name}}</td>
                    <td>{{item.cTime}}</td>
                    <td>
                        <!-- 将index作为参数传入 -->
                        <!-- <a href="#" @click="deleteData(index)">删除</a> -->
                        <a href="#" @click="showBox(item.id,index)">删除</a>
                    </td>
                </tr>
                <tr v-if="list.length==0">
                    <td colspan="4">没有品牌数据</td>
                </tr>
                <!-- 动态生成内容tr -->
            </table>
        </div>
        <transition
         enter-active-class="animated fadeInRight" 
         leave-active-class="animated fadeOutRight">
            <div class="tipbox" v-if="isShow">
                <h3>是否删除{{tempId}}号</h3>
                <button @click="confirmDel">确认</button>
                <button @click="cancelDel">取消</button>
            </div>
        </transition>

    </div>
</body>

<script>
    var vm = new Vue({
        el: '#app',
        data: {
            list: [{
                    id: 1,
                    name: "AA",
                    cTime: new Date()
                },
                {
                    id: 2,
                    name: "BB",
                    cTime: new Date()
                },
                {
                    id: 3,
                    name: "CC",
                    cTime: new Date()
                }
            ],
            newId: "",
            newName: "",
            isShow: false,
            tempId: "",
            tempIndex: ""
        },
        mounted() {
            console.log(this.$refs.inputRefId);
        },
        methods: {
            deleteData(index) {
                this.list.splice(index, 1)
            },
            addData() {
                this.list.push({
                    id: this.newId,
                    name: this.newName,
                    cTime: new Date()
                });
            },
            showBox(id, index) {
                this.tempIndex = index
                this.tempId = id
                this.isShow = !this.isShow
            },
            confirmDel() {
                this.isShow = false;
                this.deleteData(this.tempIndex)
            },
            cancelDel() {
                this.isShow = false
            }
        }
    });
</script>

</html>